package com.xzuf.communication;

import java.util.ArrayList;

import javax.swing.table.DefaultTableModel;

/**
 * @author xzgf
 * @since 2008-11-11
 * @version 1.0
 */
public class LinkManTableModel extends DefaultTableModel {

	private ArrayList<LinkerManVO> dataList = null;
	
	private static final int COLUMNCOUNT = 7;
	
	private static final String[] COLUMNNAME = new String[] {"简称","名称","公司","职务","固话","手机","地址"};
	
	public LinkManTableModel() {
		dataList = new ArrayList<LinkerManVO>();
	}
	
	public void clearBodyData() {
		dataList.clear();
		fireTableRowsDeleted(0, getRowCount());
	}
	
	public void addRow(LinkerManVO vo) {
		insertRow(vo, getRowCount());
	}
	
	public void insertRow(LinkerManVO vo,int rowIndex) {
		if(dataList == null) {
			dataList = new ArrayList<LinkerManVO>();
		}
		dataList.add(rowIndex, vo);
		fireTableRowsInserted(rowIndex, rowIndex);
	}
	
	@Override
	public boolean isCellEditable(int row, int column) {
		return false;
	}
	
	@Override
	public int getRowCount() {
		if(dataList != null) {
			return dataList.size();
		}
		return super.getRowCount();
	}
	
	@Override
	public String getColumnName(int column) {
		if(column < COLUMNCOUNT) {
			return COLUMNNAME[column];
		}
		return super.getColumnName(column);
	}
	
	@Override
	public Class<?> getColumnClass(int columnIndex) {
		return String.class;
	}
	
	@Override
	public int getColumnCount() {
		return COLUMNCOUNT;
	}
	
	//"简称","名称","公司","职务","固话","手机","地址"
	@Override
	public Object getValueAt(int row, int column) {
		if(row < dataList.size() && column < COLUMNCOUNT) {
			LinkerManVO vo = dataList.get(row);
			if(column == 0) {
				return vo.getLinkcode();
			}
			if(column == 1) {
				return vo.getLinkname();
			}
			if(column == 2) {
				return vo.getCorp();
			}
			if(column == 3) {
				return vo.getJob();
			}
			if(column == 4) {
				return vo.getTelphone();
			}
			if(column == 5) {
				return vo.getMobilephone();
			}
			if(column == 6) {
				return vo.getAdress();
			}
		}
		return super.getValueAt(row, column);
	}
}
